﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Proxy : MonoBehaviour
{
    private int flag = 0;
    private Text text;

    void Start()
    { 
        text = GetComponentInChildren<Text>();
    }

    public void dancing(string param)
    {
	text.text = "param from android: "+param;
        GameObject gameObject = GameObject.Find("dancing");  
	Dancing dancing = gameObject.GetComponent<Dancing>();
	dancing.start();
    }

    private void OnGUI()
    {
        if (GUILayout.Button("\n\nunity call \n   android method   \n\n"))
	{
	    using(AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
	    {
                using(AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject>("currentActivity"))
                {
                
	            if (flag%2==0)
	            {
	                jo.Call("androidMethod", "parameters");
	            }
	            else
	            {
	    	        jo.Call("androidMethod");
	            }
	            flag++;
	        }
	    }
        }
    }
}
